import { InputQuestion, QuestionBase, SelectQuestion, TextQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { regExp } from '@/utils/regExp';
import { Api } from '@/config/api/deptFile';
import { Api as ApiStatement } from '@/config/api/watermark';
import { Api as ApiFile } from '@/config/api/fileInfo';
import { CATEGORIZE_FROM } from '@/enums/commonEnum';
import { changeByte } from '@/utils/common';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      // new InputQuestion({
      //   key: 'code',
      //   label: '编码',
      //   value: null
      // }),
      new InputQuestion({
        key: 'name',
        label: '名称',
        value: null
      }),
      new SelectQuestion({
        key: 'status',
        label: '状态',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'WMS_ON_OR_OFF'
        }
      }),
      new TextQuestion({
        key: 'parentId',
        hide: true,
        value: null
      })
    ];
    return questions;
  }

  getTables() {
    const tables: TableBase<any>[] = [
      // new TextTable({
      //   key: 'name',
      //   value: '名称',
      //   type: 'router',
      //   state: {
      //     key: 'code',
      //     type: 'local'
      //   }
      // }),
      new TextTable({
        key: 'key',
        value: null,
        type: 'slot',
        columns: { width: 60 },
        state: {
          slotName: 'fileImg'
        }
      }),
      new TextTable({
        key: 'name',
        value: '名称',
        type: 'slot',
        columns: { width: 200 },
        state: {
          slotName: 'fileName'
        }
      }),
      new TextTable({
        key: 'code',
        value: '编码'
      }),
      new TextTable({
        key: 'watermarkingIdName',
        value: '水印'
      }),
      new TextTable({
        key: 'status',
        value: '状态',
        type: 'slot',
        state: {
          slotName: 'status'
        }
      }),
      new TextTable({
        key: 'creatorName',
        value: '创建人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '创建时间'
      }),
      new TextTable({
        key: 'modifierName',
        value: '修改人'
      }),
      new TextTable({
        key: 'modifiedTime',
        value: '修改时间'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: { fixed: 'right', width: 150 },
        handle: [
          {
            type: 'local',
            text: '详情',
            key: 'code',
            class: 'text-primary',
            state: {}
          },
          {
            type: 'delete',
            text: '删除',
            class: 'text-primary',
            url: Api.deptDelete,
            postType: 'post',
            urlName: 'id',
            state: {}
          }
        ]
      })
    ];
    return tables;
  }

  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        value: '添加',
        type: 'primary',
        class: 'icon-add',
        state: {}
      }),
      new TextTable({
        key: 'local',
        value: '删除',
        type: 'default',
        class: 'icon-delete',
        state: {}
      })
    ];
    return icons;
  }

  // 文件/目录-复制到/移动到
  getCopyQuestions(label) {
    const questions: QuestionBase<any>[] = [
      new SelectQuestion({
        key: 'toDirectoryId',
        label,
        required: true,
        prompt: '请选择',
        value: null,
        type: 'tree',
        state: {
          url: ApiFile.fileGetFoldersWithPriv,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'children',
          changeParams: [{ categorizeTo: 'categorize' }],
          extendParams: {
            categorizeFrom: CATEGORIZE_FROM.DEPT
          }
        }
      })
    ];
    return questions;
  }
  // 重命名
  getRenameQuestions() {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'OLD_NAME',
        label: '文件名称',
        value: null
      }),
      new InputQuestion({
        key: 'name',
        label: '新文件名称',
        required: true,
        prompt: '请输入，长度不可超过100个字符',
        reg: regExp.len100,
        value: null
      })
    ];
    return questions;
  }
  // 历史版本
  getVersionTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'name',
        value: '文件名称'
      }),
      new TextTable({
        key: 'size',
        value: '大小',
        type: 'custom',
        columns: {
          customRender: (data: any) => {
            return changeByte(data.value);
          }
        }
      }),
      new TextTable({
        key: 'version',
        value: '版本'
      }),
      new TextTable({
        key: 'optType',
        value: '操作记录'
      }),
      new TextTable({
        key: 'modifiedTime',
        value: '修改时间'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        handle: [
          {
            type: 'hint',
            text: '回滚',
            class: 'text-primary',
            url: '/url',
            postType: 'post',
            urlName: 'id',
            params: [{ id: 'id' }],
            // showKey: [{ key: 'status', value: 2 }],
            state: {
              hintData: {
                title: '原文件将会被覆盖，是否确定回滚该文件？'
              }
            }
          },
          {
            type: 'local',
            text: '下载',
            class: 'text-primary',
            state: {
              name: 'VERSION_DOWN'
            }
          }
        ]
      })
    ];
    return tables;
  }
  // 任务记录
  getRecordTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'name',
        value: '文件名称'
      }),
      new TextTable({
        key: 'size',
        value: '大小',
        type: 'custom',
        columns: {
          customRender: (data: any) => {
            return changeByte(data.value);
          }
        }
      }),
      new TextTable({
        key: 'version',
        value: '版本'
      }),
      new TextTable({
        key: 'opt',
        value: '类型',
        type: 'dictionary',
        state: {
          filterName: 'TASK_RECORD_OPT'
        }
      }),
      new TextTable({
        key: 'status',
        value: '状态',
        type: 'dictionary',
        state: {
          filterName: 'TASK_RECORD_STATUS'
        }
      }),
      new TextTable({
        key: 'creatorName',
        value: '创建人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '创建时间'
      })
    ];
    return tables;
  }
}

export default new HomeService();
